package com.hare.system_server.controller;


import com.hare.common.result.R;
import com.hare.system_api.dto.SysMenuDTO;
import com.hare.system_api.vo.MenuTreeVO;
import com.hare.system_server.serice.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: Hare
 * @description: 菜单相关Api
 * @author: Hare
 * @create: 2022-12-28 16:04
 * @Version 6.0.1
 **/
@RestController
@RequestMapping("/menu")
public class SysMenuController {

    @Autowired
    SysMenuService sysMenuService;


    /**
     * 获取菜单下拉框树数据
     *
     * @param sysMenuDTO 菜单信息
     * @return tree数据
     */
    @PostMapping("/treeMenuList")
    public R<List<MenuTreeVO>> selectMenuTreeList(@RequestBody(required = false) SysMenuDTO sysMenuDTO) {
        return R.success(sysMenuService.selectMenuTreeList(sysMenuDTO));
    }

    /**
     * 对应角色菜单列表树
     *
     * @param roleId 角色id
     * @return tree数据
     */
    @GetMapping("/{roleId}")
    public R<Map<String, Object>> getMenuList(@PathVariable String roleId) {
        SysMenuDTO sysMenuDTO = new SysMenuDTO();
        sysMenuDTO.setId(roleId);
        List<MenuTreeVO> menuTreeList = sysMenuService.selectMenuTreeList(sysMenuDTO);
        List<String> menuListByRoleId = sysMenuService.getMenuListByRoleId(roleId);
        Map<String, Object> map = new HashMap<>();
        map.put("menuList", menuTreeList);
        map.put("checkKeys", menuListByRoleId);
        return R.success(map);
    }
}
